package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.OrderResult;
import cn.gson.crm.model.pojo.Sendgoodsdetail;
import cn.gson.crm.model.vo.SendgoodsdetailVO;
import cn.gson.crm.service.SendGoodsDetailsService;

@Controller
public class SgdControl {

	@Autowired
	private SendGoodsDetailsService sgd;
	
	@GetMapping("/toSgd")
	public String toSgd() {
		return "zj/sgd";
	}

	@GetMapping("/getAllSgd")
	@ResponseBody
	public Map getAllSgd(int page, int rows) {
		System.out.println("contrl");
		Map map = new HashMap<>();
		Long count = sgd.count();
		List<SendgoodsdetailVO> list = sgd.getAllSgd(page, rows);
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	
	@GetMapping("/deleteSgd")
	@ResponseBody
	public OrderResult deleteSgd(Long sgdId) {
		try {
			sgd.deleteSgd(sgdId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/addSgd")
	@ResponseBody
	public OrderResult addSgd(Sendgoodsdetail sgdBean, Long custId, Long coId) {
		try {
			sgd.addSgd(sgdBean, custId, coId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
}
